// 生成二维码
import qrCode from 'qrcode'
import Base64 from 'base-64'

export function qrCodeImage (data) {
	return new Promise((resolve, reject) => {
		// toDataURL
		qrCode.toString(
			String(data), 
			{
				type: 'svg',
				errorCorrectionLevel: 'H',
				margin: 0,
				color: {
					dark: '#000',
					light: '#f8f8f8'
				}
			}, 
			(err, str) => {
				if (err) {
					console.log(err)
				}
				const base64 = Base64.encode(str)
				let imageUrl = `data:image/svg+xml;base64,${base64}`
				// console.log(imageUrl)
				resolve(imageUrl)
			}
		)
	})
 
}